const webpackMerge = require('webpack-merge');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const baseConfig = require('./config/base');
const config = require('./config/config');
const defPath = config.defPath;
const APP_PATH = defPath.APP_PATH;

// 使用 `webpack-merge` 将基础配置和新配置合并
module.exports = webpackMerge(baseConfig(), {
    entry: {    // 入口
        app: [  // 热加载配置
            defPath.ENTRY_PATH
        ],
        vendor:['react','react-dom']
    },
    output: {   // 出口
        path: defPath.DEV_PATH,     // 所有输出文件的目标路径
        // 所有输出文件的目标路径
        filename: 'js/[name].js',   // 输出文件命名
        publicPath: './',
        library:'bee',
        libraryTarget:'umd'
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                options: {
                  cacheDirectory: true,
                  presets: ['env', 'stage-2', 'react'],
                  plugins: ['transform-runtime'],
                },
            },
            {
                test: /\.tsx?$/,
                loader: 'ts-loader'
            },
            {
                test: /\.(less|css)$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ['css-loader', 'less-loader','postcss-loader']
                })
            },
            {
                test: /\.module$/i,
                use: ExtractTextPlugin.extract({
                    fallback:"style-loader",
                    use:['css-loader?modules&localIdentName=[name]__[local]-[hash:base64:5]', 'less-loader' ]
                })
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
                include: APP_PATH,
                loader: 'url-loader?limit=10000&name=images/[name].[ext]'
            },
        ]
    },
    plugins: [
        // 定义环境变量
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('development')
        }),
         new ExtractTextPlugin({
            // path:defPath.DEV_PATH,
            filename: 'css/styles.css',
            disable: false,
            allChunks: true
        }),
    ],
});